package CreationMode.single.demo05;

public class Single {

    private volatile static Boolean isFirstCreate = true ;

    // 防止放射对单列模式的破坏
    private Single() {

        synchronized (Single.class){

            if(!isFirstCreate){
                throw new RuntimeException("不能创建多个对象");
            }

            isFirstCreate = false;
        }

    }

    private static class Innner{
        private static final Single SINGLE = new Single();
    }

    public static Single getInstance(){
        return Innner.SINGLE;
    }

    // 反序列化自动调用 防止序列化
    public Object readResolve(){
        return Innner.SINGLE;
    }
}
